// 获取当前日期函数
import dayjs from "dayjs";
const dateFormat = 'YYYY-MM-DD';

export function getFormatDate(num: any) {
  // eslint-disable-next-line no-param-reassign
  num = Number(num)
  const today = new Date();
  const year = today.getFullYear(); // 年（四位数，如2023）
  const month = String(today.getMonth() + 1).padStart(2, '0'); // 月（0-11，需+1）
  const day = String(today.getDate()).padStart(2, '0'); // 日（1-31）
  const formattedDate = `${year}-${month}-${day}`;

  const yesterdayTimestamp = today.getTime() - 24 * 60 * 60 * 1000; // 当前时间戳减去一天的毫秒数
  const yesterday = new Date(yesterdayTimestamp); // 转换为昨天的日期对象

  if(num === 1){
    return [dayjs(formattedDate, dateFormat),dayjs(formattedDate, dateFormat)]
  }
  if(num === 2){
    const d  = `${yesterday.getFullYear()}-${String(yesterday.getMonth() + 1).padStart(2, '0')}-${String(yesterday.getDate()).padStart(2, '0')}`
    return [dayjs(d, dateFormat),dayjs(d, dateFormat)]
  }
  if(num === 3){
    return [dayjs(`${year}-${month}-01`, dateFormat),dayjs(formattedDate, dateFormat)]
  }
  if(num === 4){
    const s = `${year}-${String(today.getMonth()).padStart(2, '0')}-01`
    const e = `${year}-${String(today.getMonth()).padStart(2, '0')}-31`
    return [dayjs(s, dateFormat),dayjs(e, dateFormat)]
  }
  if(num === 5){
    return [dayjs(`2025-01-01`, dateFormat),dayjs(formattedDate, dateFormat)]
  }
}
